package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.noticeMapper;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Dept;
import com.gxa.pojo.Notice;
import com.gxa.service.noticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author xiejinfeng
 * @create 2021-06-15 16:29
 * @descrip:
 */
@Service
public class noticeServiceImpl implements noticeService {


    @Autowired
    private noticeMapper mapper;


    @Override
    public LayR list(MyTableParam param) {
        PageHelper.startPage(param.getPage(),param.getLimit());

        List<Notice> allForList = mapper.findAllForList(param);

        PageInfo<Notice> emplPageInfo = new PageInfo<>(allForList);

        return new LayR(0,"success",emplPageInfo.getList(),emplPageInfo.getTotal());
    }

    @Override
    public R deleteOne(Integer id) {

        mapper.deleteOneById(id);
        return new R(200,"删除成功");

    }

    @Override
    public R deleteAll(String[] ids) {
        mapper.deleteAll(ids);
        return new R(200,"删除成功");
    }

    @Override
    public R add(Notice notice) {
        notice.setReleaseTime(new Timestamp(System.currentTimeMillis()));

        mapper.save(notice);

        return new R(200,"添加成功");
    }

    @Override
    public R findById(Integer id) {

        Notice notice = mapper.findByPk(id);

        return new R(200,"success",notice);
    }

    @Override
    public R edit(Notice notice) {

        mapper.update(notice);

        return new R(200,"修改成功");
    }
}
